# if语句
cars = ["audi","bmw","subaru","toyota"]
for car in cars:
    if car == "bmw":
        print(car.upper())
    else:
        print(car.lower())

# 忽略大小写
#可以写成
cars = ["audi","Bmw","subaru","toyota"]
for car in cars:
    if car.lower() == "bmw":
        print(car.upper())
    else:
        print(car.lower())

#检查是否不等
requested_topping = "mushrooms"
if requested_topping != "anchovies":
    print("Hold the anchovies!")


# 检查多个条件
## 使用 and 检查多个条件
age_0 = 22
age_1 = 18
print(age_0 >= 21 and age_1 >=21)
age_1 = 23
print((age_0 >=21) and (age_1 >= 21)) #增加可读性

## 使用 or 检查多个条件
age_0 = 22
age_1 = 18
print(age_0 >= 21 or age_1 >= 21)
age_0 = 17
print(age_0 >= 21 or age_1 >= 21)


# 检查特定值是否在列表中
requested_toppings = ["mushrooms","onins","onions","pineapple"]
print("mushrooms" in requested_toppings)
print("pepperoni" in requested_toppings)

# 检查特定值是否不在列表中
banned_users = ["andrew","carolina","david"]
user = "marie"
if user not in banned_users:
    print(f"{user.title()}, you can pose a response if you wish.")

# 布尔表达式
game_active = True
can_edit = False


# if 语句
age = 19
if age >= 18:
    print("You are old enough to vote!")
    print("Have you registered to vote yes ?")

# if-else 语句
age = 17
if age >= 18:
    print("You are old enough to vote!")
    print("Have you registered to vote yes ?")
else:
    print("Sorry,you are too young to vote.")
    print("Please register to vote as soon as you turn 18!")

# if-elif-else
age = 12
if age < 4:
    print("Your admission cost is $0.")
elif age < 18:
    print("Your admission cost is $24.")
else:
    print("Your admission cost is $40")

# 多个 elif 代码块
age = 12
if age < 4:
    price = 0
elif age < 18:
    price = 25
elif age < 65:
    price = 40
else:
    price = 20
print(f"Your admission cost is ${price}")

#省略 else
age = 12
if age < 4:
    price = 0
elif age < 18:
    price = 25
elif age < 65:
    price = 40
elif age >= 65:
    price = 20
print(f"Your admission cost is ${price}")

# 简单 for + if 组合
requested_toppings = ["mushrooms","green peppers","extra cheese"]
for requested_topping in requested_toppings:
    if requested_topping == "green peppers":
        print("Sorry, we are out green peppers right now.")
    else:
        print(f"Adding {requested_topping}")
print("\nFinished making your pizza!\n")

#确认列表非空  对于 0、空值、单双引号空字符串“”、空列表[]、空元祖()、空字典{}，都会是 False
requested_toppings = []
if requested_toppings:
    for requested_topping in requested_toppings:
        print(f"Adding {requested_topping}")
    print("\nFinished making your pizza!")
else:
    print("Are you sure you want a plain pizza?")

